package com.carpedil.demo.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carpedil.demo.po.Role;
import com.carpedil.demo.po.UserRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/** @author Administrator */
@Repository
public interface UserRoleMapper extends BaseMapper<UserRole> {
  /**
   * getRolesById
   *
   * @param userId userId
   * @return List<Role>
   */
  @Select(
      "SELECT r.*  "
          + " from user_role ur "
          + " INNER JOIN users u on u.id = ur.fk_user_id "
          + " INNER JOIN roles r on r.pk_id = ur.fk_role_id "
          + " WHERE u.id = #{userId}")
  @ResultMap("com.carpedil.demo.dao.RoleMapper.roleMap")
  List<Role> getRolesById(@Param("userId") Integer userId);
}
